<template>
  <z-modal
    :width="modalWidth"
    :visible="visible"
    :title="title"
    destroyOnClose
    switchFullscreen
    @ok="handleSubmit"
    @cancel="close"
    cancelText="关闭"
  >
    <a-card :bordered="false">
      <a-form @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :span="10">
            <a-form-item label="合同名称" :label-col="labelCol" :wrapper-col="wrapperCol">
              <a-input-search placeholder="请输入合同名称" v-model="queryParam.name" @search="searchQuery" />
            </a-form-item>
          </a-col>
          <a-col :span="10">
            <a-form-item label="合同编号" :label-col="labelCol" :wrapper-col="wrapperCol">
              <a-input-search placeholder="请输合同编号" v-model="queryParam.num" @search="searchQuery" />
            </a-form-item>
          </a-col>
          <a-col :span="4">
            <a-form-item>
              <a-button type="primary" icon="reload" style="margin-left: 8px" @click="searchReset()">重置</a-button>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
      <!--合同列表-->
      <vxe-grid
        id="selectContractList"
        ref="vxeTable"
        :toolbarConfig="false"
        :checkbox-config="{trigger:this.multi?'row':'cell'}"
        :radio-config="{trigger:!this.multi?'row':'cell'}"
        :rowConfig="{ keyField: 'id',isCurrent:true }"
        v-bind="gridOptions"
        v-on="listeners"
        @radio-change="onRadioSelectChange"
      >
      </vxe-grid>
    </a-card>
  </z-modal>
</template>

<script>
import VxeTableListMixin from '@/mixins/VxeTableListMixin'

export default {
  name: 'SelectContractList',
  mixins: [VxeTableListMixin],
  props: {
    modalWidth: {
      type: Number,
      default: 1250,
      required: false
    },
    multi: {
      type: Boolean,
      default: false,
      required: false
    },
  },
  data() {
    return {
      title: '选择合同',
      loading: false,
      form: this.$form.createForm(this),
      visible: false,
      columns: [
        { type: this.multi ? 'checkbox' : 'radio', width: 50 },
        { type: 'seq', width: 40 },
        { title: '合同名称', field: 'name' },
        { title: '合同编号', field: 'num' },
        { title: '客户名称', field: 'customerName' },
        { title: '销售机会', field: 'businessName' },
        { title: '合同总价', field: 'money' }
      ],
      url: {
        list: "/contract/list",
      },
    }
  },
  methods: {
    showModal() {
      this.visible = true
      this.loadData()
      this.form.resetFields()
    },
    close() {
      this.searchReset(0)
      this.visible = false
    },
    handleSubmit() {
      this.$emit('ok', this.selectionRows, this.selectedRowKeys)
      this.close()
    },
    searchQuery() {
      this.loadData('reload')
    },
    onRadioSelectChange({ row }) {
      this.selectionRows = [row]
      this.selectedRowKeys = [row.id]
    }
  }
}
</script>
<style>
.jeecg-form-container-disabled{
    cursor: not-allowed;
}
</style>
